package pl.lodz.p.browarex.utils;

import pl.lodz.p.browarex.model.AnalysiesListType;
import pl.lodz.p.browarex.model.AnalysisType;
import pl.lodz.p.browarex.model.Customer;
import pl.lodz.p.browarex.model.enums.AnalysisTypeEnum;
import pl.lodz.p.browarex.services.interfaces.IAnalysisTypeService;

public class Utils {

	public static double getDiscount(Customer loggedCustomer,
			IAnalysisTypeService analysisTypeService) {
		AnalysisType analysisType = analysisTypeService
				.loadByCustomerID(loggedCustomer.getCustomerID());
		double discount = 0;
		if (analysisType != null) {
			for (AnalysiesListType listType : analysisType.getAnalysies()) {
				if (listType.getType().equals(AnalysisTypeEnum.DISCOUNT)) {
					if (discount < listType.getDiscountValue()) {
						discount = listType.getDiscountValue();
					}
				}
			}
		}
		return discount / 100;
	}
}
